﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="EditOrderFrm.aspx.cs" Inherits="WebApp.EditOrderFrm" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <link rel="stylesheet" type="text/css" href="css/newStyle.css" />
    <link rel="stylesheet" type="text/css" href="js/jquery-easyui-1.3.2/themes/default/easyui.css" />
    <link rel="stylesheet" type="text/css" href="js/jquery-easyui-1.3.2/themes/icon.css" />

    <script type="text/javascript" src="js/common.js"></script>

    <script type="text/javascript" src="js/jquery-easyui-1.3.2/jquery-1.8.0.min.js"></script>

    <script type="text/javascript" src="js/jquery-easyui-1.3.2/jquery.easyui.min.js"></script>

    <script type="text/javascript" src="js/Jquery.Query.js"></script>

    <script type="text/javascript">
        //页面加载
        $(document).ready(function() {
            initBtns();
            initParams();
            initData();
        });

        function initParams() {
            var orderId = $.query.get('OrderId');
            if (orderId) {
                $('#editId').val(orderId);
                editOrder(orderId);
            }
        }

        function initData() {
            $('#eAgent').combogrid('disable');
            $('#qOrderStatus').combobox('reload', 'JSONHandler.ashx?DataType=OrderStatus');
            $('#eOrderDate').datebox('setValue', DateFormatter(new Date()));
            $('#eApplyDate').datebox('setValue', DateFormatter(new Date()));


            $.getJSON("JSONHandler.ashx?DataType=StowageMethod", function(result) {
                $('#eStowageMethod').combobox('loadData', result);
            });

            $.getJSON("JSONHandler.ashx?DataType=CustomsStatus", function(result) {
                $('#eCustomsStatus').combobox('loadData', result);
                $('#eCustomsStatus').combobox('setValue', 0);
            });

            $.getJSON("JSONHandler.ashx?DataType=User", function(result) {
                $('#eAgent').combogrid("grid").datagrid("loadData", result);
                $('#eBizMan').combogrid("grid").datagrid("loadData", result);
            });

            $.getJSON("JSONHandler.ashx?DataType=Client", function(result) {
                $('#eClient').combogrid("grid").datagrid("loadData", result);
            });

            $.getJSON("JSONHandler.ashx?DataType=Port", function(result) {
                $('#eStartPort').combobox('loadData', result);
                $('#eEndPort').combobox('loadData', result);
                $('#eReturnPort').combobox('loadData', result);
                $('#eBGEndPort').combobox('loadData', result);
            });

            $.getJSON("JSONHandler.ashx?DataType=ImptAndExpt", function(result) {
                $('#eImptAndExpt').combobox('loadData', result);
            });

            $.getJSON("JSONHandler.ashx?DataType=StowageArea", function(result) {
                $('#eStowageArea').combobox('loadData', result);
            });

            $.getJSON("JSONHandler.ashx?DataType=TCAgent", function(result) {
                $('#eTCAgent').combobox('loadData', result);
            });

            $.getJSON("JSONHandler.ashx?DataType=BGAgent", function(result) {
                $('#eBGAgent').combobox('loadData', result); //角色==业务员隐藏
            });

            $.getJSON("JSONHandler.ashx?DataType=TransferType", function(result) {
                $('#eTransferType').combobox('loadData', result);
            });
            resetFrm(true);
        }

        function resetFrm(first) {
            if (!first) {
                $('#fm').form('clear');
                $('#fmTC').form('clear');
                $('#fmBG').form('clear');
            }
            $('#editId').val('');
            $('#eOrderDate').datebox('setValue', DateFormatter(new Date()));
            $('#eApplyDate').datebox('setValue', DateFormatter(new Date()));

            var res = WebApp.EditOrderFrm.GetCurrentUser().value;
            $('#eBizMan').combogrid('setValue', res);
            $('#eAgent').combogrid('setValue', res);
            $('#TBWF').datagrid('loadData', { total: 0, rows: [] });
            $('#eCustomsStatus').combobox('setValue', 0);
        }       
    </script>

    <style type="text/css">
        .fTitle
        {
            font-size: 14px;
            color: #3B639F;
            padding: 10px;
            font-weight: bold;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    </form>
    <div class="fTitle" id="topTitle">
        工作单信息&nbsp;&nbsp;当前环节：<span id="spnOrderStatus"></span>&nbsp;&nbsp;单号：<input type="text"
            id="spnOrderCode" style="border-style: none" /></div>
    <div id="tabs" class="easyui-tabs" style="width: 700px; height: 240px">
        <div title="基本信息" style="padding: 10px">
            <form id="fm">
            <table style="border: 0px; padding: 2px; width: 100%">
                <tr>
                    <td style="text-align: left">
                        接单时间：
                    </td>
                    <td style="text-align: left">
                        <input id="eOrderDate" name="orderTime" class="easyui-datebox" data-options="formatter:DateFormatter,parser:DateParser"
                            style="width: 100px" required="true" />
                    </td>
                    <td style="text-align: left">
                        业务员：
                    </td>
                    <td style="text-align: left">
                        <input class="easyui-combogrid" required="true" id="eBizMan" name="operator" style="width: 150px"
                            data-options="  
            panelWidth: 150,  
            idField: 'id',  
            textField: 'userName',
            columns: [[{field:'userName',title:'名称',width:150}               
            ]],  
            fitColumns: true  
        ">
                    </td>
                    <td style="text-align: left">
                        客服：
                    </td>
                    <td style="text-align: left">
                        <input class="easyui-combogrid" required="true" id="eAgent" name="eAgent" style="width: 150px"
                            data-options="  
            panelWidth: 150,  
            idField: 'id',  
            textField: 'userName', 
            columns: [[   
                {field:'userName',title:'名称',width:150}               
            ]],  
            fitColumns: true 
        ">
                    </td>
                </tr>
                <tr>
                    <td style="text-align: left">
                        委托方：
                    </td>
                    <td style="text-align: left">
                        <input class="easyui-combogrid" id="eClient" name="client" style="width: 150px" required="true"
                            data-options="  
            panelWidth: 150,  
            idField: 'id',  
            textField: 'fullName',  
            columns: [[  
                {field:'fullName',title:'名称',width:150}              
            ]],  
            fitColumns: true  
        ">
                    </td>
                    <td style="text-align: left">
                        发票台头：
                    </td>
                    <td style="text-align: left">
                        <input type="text" id="eInvoiceHeader" name="invoiceHeader" style="width: 150px" />
                    </td>
                    <td style="text-align: left">
                        联系方式：
                    </td>
                    <td style="text-align: left">
                        <input type="text" id="eContactInfo" name="contactInfo" style="width: 150px" />
                    </td>
                </tr>
                <tr>
                    <td style="text-align: left">
                        提单号：
                    </td>
                    <td style="text-align: left">
                        <input type="text" id="eCCode" name="cCode" style="width: 150px" required="true" />
                    </td>
                    <td style="text-align: left">
                        起运港：
                    </td>
                    <td style="text-align: left">
                        <input class="easyui-combobox" id="eStartPort" name="startPort" data-options="valueField:'id',textField:'name'"
                            style="width: 150px;">
                    </td>
                    <td style="text-align: left">
                        目的港：
                    </td>
                    <td style="text-align: left">
                        <input class="easyui-combobox" id="eEndPort" name="endPort" data-options="valueField:'id',textField:'name'"
                            style="width: 150px;">
                    </td>
                </tr>
                <tr>
                    <td style="text-align: left">
                        进出口：
                    </td>
                    <td style="text-align: left">
                        <input class="easyui-combobox" id="eImptAndExpt" name="imptAndExpt" data-options="valueField:'id',textField:'name'"
                            style="width: 150px;">
                    </td>
                    <td style="text-align: left">
                        截关日期：
                    </td>
                    <td style="text-align: left">
                        <input id="eCustomsDeadline" name="customsDeadline" class="easyui-datebox" data-options="formatter:DateFormatter,parser:DateParser"
                            style="width: 100px" />
                    </td>
                    <td style="text-align: left">
                        装柜形式：
                    </td>
                    <td style="text-align: left">
                        <input class="easyui-combobox" id="eStowageMethod" name="stowageMethod" data-options="valueField:'id',textField:'name'"
                            style="width: 150px;">
                    </td>
                </tr>
                <tr>
                    <td style="text-align: left">
                        备注：
                    </td>
                    <td style="text-align: left">
                        <textarea cols="15" rows="1" id="eMemo" name="memo"></textarea>
                    </td>
                    <td style="text-align: center" colspan="4">
                        <input type="checkbox" id="eHasTrailer" name="eHasTrailer" />是否拖车&nbsp;&nbsp;<input
                            type="checkbox" id="eHasInvoice" name="hasInvoice" />有无发票&nbsp;&nbsp;<input type="checkbox"
                                id="eIsCustoms" name="isCustoms" />是否报关&nbsp;&nbsp;<input type="checkbox" id="eIsOcean"
                                    name="isOcean" />是否海运
                    </td>
                </tr>
            </table>
            </form>
        </div>
        <div title="拖车信息" style="padding: 10px">
            <form id="fmTC">
            <table style="border: 0px; padding: 2px; width: 100%">
                <tr>
                    <td style="text-align: left">
                        提柜堆场：
                    </td>
                    <td style="text-align: left">
                        <input class="easyui-combobox" id="eStowageArea" name="stowageArea" data-options="valueField:'id',textField:'name'"
                            style="width: 130px;" required="true">
                    </td>
                    <td style="text-align: left">
                        装货期限：
                    </td>
                    <td style="text-align: left">
                        <input id="eDeadline" name="deadline" class="easyui-datetimebox" style="width: 130px"
                            data-options="formatter:DateTimeFormatter,showSeconds:false" />
                    </td>
                    <td style="text-align: left">
                        还柜码头：
                    </td>
                    <td style="text-align: left">
                        <input class="easyui-combobox" id="eReturnPort" name="returnPort" data-options="valueField:'id',textField:'name'"
                            style="width: 130px;">
                    </td>
                </tr>
                <tr>
                    <td style="text-align: left">
                        拖车行：
                    </td>
                    <td style="text-align: left">
                        <input class="easyui-combobox" id="eTCAgent" name="tcAgent" data-options="valueField:'id',textField:'name'"
                            style="width: 130px;" required="true">
                    </td>
                    <td style="text-align: left">
                        装柜联系：
                    </td>
                    <td style="text-align: left">
                        <input type="text" id="eStowageContact" name="stowageContact" style="width: 130px" />
                    </td>
                    <td style="text-align: left">
                        操作联系：
                    </td>
                    <td style="text-align: left">
                        <input type="text" id="eOpContact" name="opContact" style="width: 130px" />
                    </td>
                </tr>
                <tr>
                    <td style="text-align: left">
                        柜量柜型：
                    </td>
                    <td style="text-align: left">
                        <input type="text" id="eSpecs" name="specs" style="width: 130px" />
                    </td>
                    <td style="text-align: left">
                        装柜地址：
                    </td>
                    <td style="text-align: left" colspan="3">
                        <input type="text" id="eTCAddress" name="tcAddress" style="width: 250px" />
                    </td>
                </tr>
                <tr>
                    <td style="text-align: left">
                        拖车备注：
                    </td>
                    <td style="text-align: left">
                        <textarea cols="20" rows="1" id="eTCMemo" name="tcMemo"></textarea>
                    </td>
                    <td style="text-align: center" colspan="4">
                        运费：<input type="text" id="eTCCharge" name="tcCharge" style="width: 70px" class="easyui-numberbox"
                            data-options="min:0,precision:2" />&nbsp;&nbsp;<input type="checkbox" id="eIsPonderation"
                                name="isPonderation" />是否过磅
                    </td>
                </tr>
            </table>
            </form>
        </div>
        <div title="报关信息" style="padding: 10px">
            <form id="fmBG">
            <div id="pBG" class="easyui-panel" title="报关情况" style="width: 660px; height: 150px;
                padding: 5px;">
                <table style="border: 0px; padding: 2px; width: 100%">
                    <tr>
                        <td style="text-align: left">
                            报关行：
                        </td>
                        <td style="text-align: left">
                            <input class="easyui-combobox" id="eBGAgent" name="bgAgent" data-options="valueField:'id',textField:'name'"
                                style="width: 130px;" required="true">
                        </td>
                        <td style="text-align: left">
                            报关状态：
                        </td>
                        <td style="text-align: left">
                            <input class="easyui-combobox" id="eCustomsStatus" name="customsStatus" data-options="valueField:'Value',textField:'Name'"
                                style="width: 100px;" required="true">
                        </td>
                        <td style="text-align: left">
                            放行时间：
                        </td>
                        <td style="text-align: left">
                            <input id="eBGPassTime" name="bgPassTime" class="easyui-datetimebox" style="width: 130px"
                                data-options="formatter:DateTimeFormatter,showSeconds:false" />
                        </td>
                    </tr>
                    <tr>
                        <td style="text-align: left">
                            申报时间：
                        </td>
                        <td style="text-align: left">
                            <input id="eApplyDate" class="easyui-datebox" data-options="formatter:DateFormatter,parser:DateParser"
                                style="width: 100px" required="true" />
                        </td>
                        <td style="text-align: left">
                            中转类型：
                        </td>
                        <td style="text-align: left">
                            <input class="easyui-combobox" id="eTransferType" name="transferType" data-options="valueField:'id',textField:'name'"
                                style="width: 130px;">
                        </td>
                        <td style="text-align: left">
                            电话：
                        </td>
                        <td style="text-align: left">
                            <input type="text" id="eBGTel" style="width: 130px" />
                        </td>
                    </tr>
                    <tr>
                        <td style="text-align: left">
                            交条地址：
                        </td>
                        <td style="text-align: left">
                            <input type="text" id="eBGAddress" style="width: 130px" />
                        </td>
                        <td style="text-align: left">
                            联系人：
                        </td>
                        <td style="text-align: left">
                            <input type="text" id="eBGContactMan" style="width: 130px" />
                        </td>
                        <td style="text-align: left">
                            报关备注：
                        </td>
                        <td style="text-align: left">
                            <input type="text" id="eBGMemo" style="width: 130px" />
                        </td>
                    </tr>
                    <tr>
                        <td colspan="6">
                            <input type="checkbox" id="eIsOffer" />交单&nbsp;<input type="checkbox" id="eIsCheck" />查验&nbsp;<input
                                type="checkbox" id="eIsPass" />放行&nbsp;<input type="checkbox" id="eNotice" />通知&nbsp;<input
                                    type="checkbox" id="eIsDrawback" />是否退税&nbsp;<input type="checkbox" id="eIsKdsk" />扣单收款
                        </td>
                    </tr>
                </table>
            </div>
            <div id="pHY" class="easyui-panel" title="海运情况" style="width: 660px; height: 150px;
                padding: 5px;">
                <table style="border: 0px; padding: 2px; width: 100%">
                    <tr>
                        <td style="text-align: left">
                            收货人：
                        </td>
                        <td style="text-align: left">
                            <input type="text" id="eReceiver" style="width: 130px" />
                        </td>
                        <td style="text-align: left">
                            通知人：
                        </td>
                        <td style="text-align: left">
                            <input type="text" id="eNotifier" style="width: 130px" />
                        </td>
                        <td style="text-align: left">
                            目的港：
                        </td>
                        <td style="text-align: left">
                            <input class="easyui-combobox" id="eBGEndPort" name="endPort" data-options="valueField:'id',textField:'name'"
                                style="width: 150px;">
                        </td>
                    </tr>
                    <tr>
                        <td style="text-align: left">
                            目的地：
                        </td>
                        <td style="text-align: left">
                            <input type="text" id="eDestination" style="width: 130px" />
                        </td>
                        <td style="text-align: left">
                            船名：
                        </td>
                        <td style="text-align: left">
                            <input type="text" id="eBoatName" style="width: 130px" />
                        </td>
                        <td style="text-align: left">
                            航次：
                        </td>
                        <td style="text-align: left">
                            <input type="text" id="eRunNum" style="width: 130px" />
                        </td>
                    </tr>
                    <tr>
                        <td style="text-align: left">
                            船公司：
                        </td>
                        <td style="text-align: left">
                            <input type="text" id="eBoatCorp" style="width: 130px" />
                        </td>
                        <td style="text-align: left">
                            要求股东：
                        </td>
                        <td style="text-align: left">
                            <input type="text" id="eStockholder" style="width: 130px" />
                        </td>
                        <td style="text-align: left">
                            订舱备注：
                        </td>
                        <td style="text-align: left">
                            <input type="text" id="eBookingMemo" style="width: 130px" />
                        </td>
                    </tr>
                    <tr>
                        <td style="text-align: left">
                            运输要求：
                        </td>
                        <td style="text-align: left" colspan="5">
                            <input type="text" id="eDemand" />
                        </td>
                    </tr>
                </table>
            </div>
            <table id="TBHX" class="easyui-datagrid" title="核销信息" style="width: 660px; height: 200px"
                data-options="toolbar:'#dlg-HXButtons',singleSelect:true,collapsible:true,url:'',onClickRow: onClickHXRow">
                <thead>
                    <tr>
                        <th data-options="field:'code',width:80,editor:'text'">
                            核销单号
                        </th>
                        <th data-options="field:'status',width:60, editor:{  
                            type:'combobox',  
                            options:{  
                                valueField:'Name',  
                                textField:'Name',  
                                url:'JSONHandler.ashx?DataType=CustomsStatus',  
                                required:true  
                            }}">
                            状态
                        </th>
                        <th data-options="field:'customsCode',width:80,editor:'text'">
                            报关单号
                        </th>
                        <th data-options="field:'corp',width:80,editor:'text'">
                            报关单位
                        </th>
                        <th data-options="field:'backTime',formatter: Common.DateFormatter,width:70,editor:{type:'datebox',options:{formatter: DateFormatter}}">
                            回单时间
                        </th>
                        <th data-options="field:'backClientTime',formatter: Common.DateFormatter,width:80,editor:{type:'datebox',options:{formatter: DateFormatter}}">
                            退回客户时间
                        </th>
                        <th data-options="field:'corpName',width:100,editor:'text'">
                            公司名称
                        </th>
                        <th data-options="field:'title',width:100,editor:'text'">
                            核销台头
                        </th>
                        <th data-options="field:'memo',width:100,editor:'text'">
                            备注
                        </th>
                    </tr>
                </thead>
            </table>
            </form>
        </div>
        <div title="货物信息" style="padding: 10px">
            <table id="TBCase" class="easyui-datagrid" title="箱号" style="width: 660px; height: 200px"
                data-options="toolbar:'#TB-CaseButtons',singleSelect:true,collapsible:true,url:'',onDblClickRow: showCaseInfo,onSelect: selectCaseRow">
                <thead>
                    <tr>
                        <th data-options="field:'code',width:70">
                            箱号
                        </th>
                        <th data-options="field:'model',width:70">
                            箱型
                        </th>
                        <th data-options="field:'title',width:70">
                            封号
                        </th>
                        <th data-options="field:'carNo',width:70">
                            车牌号
                        </th>
                        <th data-options="field:'check',width:70">
                            查验封
                        </th>
                        <th data-options="field:'trailer',width:70">
                            拖车
                        </th>
                        <th data-options="field:'driver',width:70">
                            司机
                        </th>
                        <th data-options="field:'tel',width:70">
                            电话
                        </th>
                        <th data-options="field:'memo',width:70">
                            备注
                        </th>
                    </tr>
                </thead>
            </table>
            <table id="TBCargo" class="easyui-datagrid" title="货物" style="width: 660px; height: 200px"
                data-options="toolbar:'#TB-CargoButtons',singleSelect:true,collapsible:true,url:'',onDblClickRow: showCargoInfo">
                <thead>
                    <tr>
                        <th data-options="field:'cargoName',width:70">
                            货物名称
                        </th>
                        <th data-options="field:'amount',width:70">
                            数量
                        </th>
                        <th data-options="field:'PackageTypeName',width:70">
                            包装种类
                        </th>
                        <th data-options="field:'hairWeight',width:70">
                            毛重
                        </th>
                        <th data-options="field:'netWeight',width:70">
                            净重
                        </th>
                        <th data-options="field:'volume',width:70">
                            体积
                        </th>
                        <th data-options="field:'caseAmount',width:70">
                            箱量
                        </th>
                        <th data-options="field:'marker',width:70">
                            唛头
                        </th>
                        <!--
                            <th data-options="field:'memo',width:70">
                                备注
                            </th>
                            -->
                    </tr>
                </thead>
            </table>
        </div>
        <div title="文件信息" style="padding: 10px">
            <table id="TBAttach" class="easyui-datagrid" title="文件信息" style="width: 660px; height: 200px"
                data-options="toolbar:'#TB-AttachButtons',singleSelect:true,collapsible:true,url:''">
                <thead>
                    <tr>
                        <th data-options="field:'attachName',width:100">
                            文件名称
                        </th>
                        <th data-options="field:'size',width:100">
                            文件大小
                        </th>
                        <th data-options="field:'ext',width:100">
                            文件类型
                        </th>
                        <th data-options="field:'createTime',width:100">
                            上传时间
                        </th>
                    </tr>
                </thead>
            </table>
        </div>
        <div title="费用维护" style="padding: 10px">
            <table id="TBYS" class="easyui-datagrid" title="应收费用" style="width: 660px; height: 200px"
                data-options="toolbar:'#TB-YSButtons',singleSelect:true,collapsible:true,url:'',onDblClickRow: showYSInfo">
                <thead>
                    <tr>
                        <th data-options="field:'ItemName',width:70">
                            应收费目
                        </th>
                        <th data-options="field:'amount',width:70">
                            金额
                        </th>
                        <th data-options="field:'UnitName',width:50">
                            币制
                        </th>
                        <th data-options="field:'TargetName',width:150">
                            结算对象
                        </th>
                        <th data-options="field:'code',width:70">
                            账单号
                        </th>
                        <th data-options="field:'isVerify',width:30,formatter: function(value,row,index){
				if (row.isVerify==true){
					return '是';
				} else {
					return '否';
				}
			}">
                            审核
                        </th>
                        <th data-options="field:'verifyMan',width:80,hidden:true">
                            审核人
                        </th>
                        <th data-options="field:'verifyTime',formatter: Common.DateFormatter,width:80">
                            审核日期
                        </th>
                        <th data-options="field:'operator',width:60,hidden:true">
                            制单人
                        </th>
                        <th data-options="field:'createTime',formatter: Common.DateFormatter,width:80">
                            制单日期
                        </th>
                        <th data-options="field:'memo',width:100,hidden:true">
                            备注
                        </th>
                    </tr>
                </thead>
            </table>
            <table id="TBYF" class="easyui-datagrid" title="应付费用" style="width: 660px; height: 200px"
                data-options="toolbar:'#TB-YFButtons',singleSelect:true,collapsible:true,url:'',onDblClickRow: showYFInfo">
                <thead>
                    <tr>
                        <th data-options="field:'ItemName',width:70">
                            应付费目
                        </th>
                        <th data-options="field:'amount',width:70">
                            金额
                        </th>
                        <th data-options="field:'UnitName',width:50">
                            币制
                        </th>
                        <th data-options="field:'TargetName',width:150">
                            结算对象
                        </th>
                        <th data-options="field:'code',width:70">
                            账单号
                        </th>
                        <th data-options="field:'isVerify',width:50,formatter: function(value,row,index){
				if (row.isVerify==true){
					return '是';
				} else {
					return '否';
				}}">
                            审核
                        </th>
                        <th data-options="field:'verifyMan',width:70,hidden:true">
                            审核人
                        </th>
                        <th data-options="field:'verifyTime',formatter: Common.DateFormatter,width:80">
                            审核日期
                        </th>
                        <th data-options="field:'operator',width:60,hidden:true">
                            制单人
                        </th>
                        <th data-options="field:'createTime',formatter: Common.DateFormatter,width:80">
                            制单日期
                        </th>
                        <th data-options="field:'memo',width:100,hidden:true">
                            备注
                        </th>
                    </tr>
                </thead>
            </table>
        </div>
    </div>
    <br />
    <table id="TBWF" class="easyui-datagrid" title="工作流程" style="width: 700px; height: 150px"
        data-options="singleSelect:true,collapsible:true,url:''">
        <thead>
            <tr>
                <th data-options="field:'FlowStatus',width:90">
                    环节
                </th>
                <th data-options="field:'Operator',width:100">
                    处理人
                </th>
                <th data-options="field:'HandleText',width:90">
                    处理情况
                </th>
                <th data-options="field:'OPTime',width:100,formatter: Common.DateFormatter">
                    处理时间
                </th>
                <th data-options="field:'Comment',width:200">
                    处理意见
                </th>
                <th data-options="field:'NextOperator',width:100">
                    下一环节处理人
                </th>
            </tr>
        </thead>
    </table>
    <input type="hidden" id="editId" />
    <div id="dlg-buttons" style="padding: 10px">
        <a id="btnSaveBase" href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-ok"
            onclick="saveOrder()">保存基本信息</a> <a id="btnSaveTC" href="javascript:void(0)" class="easyui-linkbutton"
                iconcls="icon-ok" onclick="saveTC()">保存拖车信息</a> <a id="btnDeleteTC" href="javascript:void(0)"
                    class="easyui-linkbutton" iconcls="icon-remove" onclick="clearTC()">删除拖车信息</a>
        <a id="btnPrintWTS" href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-print"
            onclick="printWTS()">打印派车委托书</a> <a id="btnSaveBG" href="javascript:void(0)" class="easyui-linkbutton"
                iconcls="icon-ok" onclick="saveBG()">保存报关信息</a> <a id="btnDeleteBG" href="javascript:void(0)"
                    class="easyui-linkbutton" iconcls="icon-remove" onclick="deleteBG()">删除报关信息</a>
        <a id="btnAddXH" href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-add"
            onclick="addCase()">添加箱号</a> <a id="btnDeleteXH" href="javascript:void(0)" class="easyui-linkbutton"
                iconcls="icon-remove" onclick="deleteCase()">删除箱号</a> <a id="btnAddHW" href="javascript:void(0)"
                    class="easyui-linkbutton" iconcls="icon-add" onclick="addCargo()">添加货物</a>
        <a id="btnDeleteHW" href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-remove"
            onclick="deleteCargo()">删除货物</a> <a id="btnUpload" href="javascript:void(0)" class="easyui-linkbutton"
                iconcls="icon-back" onclick="uploadFile()">上传文件</a> <a id="btnDownload" href="javascript:void(0)"
                    class="easyui-linkbutton" iconcls="icon-reload" onclick="downloadFile()">下载文件</a>
        <a id="btnDeleteFile" href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-remove"
            onclick="deleteFile()">删除文件</a> <a id="btnAddYS" href="javascript:void(0)" class="easyui-linkbutton"
                iconcls="icon-add" onclick="addFee(1)">添加应收</a> <a id="btnDeleteYS" href="javascript:void(0)"
                    class="easyui-linkbutton" iconcls="icon-remove" onclick="deleteYS()">删除应收</a>
        <a id="btnAddYF" href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-add"
            onclick="addFee(2)">添加应付</a> <a id="btnDeleteYF" href="javascript:void(0)" class="easyui-linkbutton"
                iconcls="icon-remove" onclick="deleteYF()">删除应付</a> <a id="btnWF" href="javascript:void(0)"
                    class="easyui-linkbutton" iconcls="icon-back" onclick="showWF()">单据流转</a>
    </div>
    <div id="dlg-HXButtons">
        <a id="btnAddHX" href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-add"
            onclick="appendHX()" plain="true">添加行</a> <a id="btnDeleteHX" href="javascript:void(0)"
                class="easyui-linkbutton" iconcls="icon-remove" onclick="removeHX()" plain="true">
                删除行</a> <a id="btnSaveHX" href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-save"
                    onclick="saveHX()" plain="true">结束编辑</a> <a id="btnRejectHX" href="javascript:void(0)"
                        class="easyui-linkbutton" iconcls="icon-undo" onclick="rejectHX()" plain="true">
                        撤销</a></div>
    <div id="win" style="text-align: center">
        <iframe id="winFrame" src="" style="width: 0px; height: 0px" frameborder="0" scrolling="no">
        </iframe>
    </div>
</body>

<script type="text/javascript">
    function initBtns() {
        $('#tabs').tabs({
            onSelect: function(title, index) {
                //alert(title + ' is selected;index=' + index);
                var id = $('#editId').val();
                $("div#dlg-buttons .easyui-linkbutton").not("#btnWF").hide();
                switch (index) {
                    case 0:
                        bindBase(id);
                        bindFlow(id);

                        $('#btnSaveBase').show();
                        break;
                    case 1:
                        bindTC(id);
                        $('#btnSaveTC').show();
                        $('#btnDeleteTC').show();
                        $('#btnPrintWTS').show();
                        break;
                    case 2:
                        bindBG(id);
                        $('#btnAddHX').show();
                        $('#btnDeleteHX').show();
                        $('#btnSaveBG').show();
                        $('#btnDeleteBG').show();
                        break;
                    case 3:
                        bindCase(id);
                        $('#btnAddXH').show();
                        $('#btnDeleteXH').show();
                        $('#btnAddHW').show();
                        $('#btnDeleteHW').show();
                        break;
                    case 4:
                        bindFile(id);
                        $('#btnUpload').show();
                        $('#btnDownload').show();
                        $('#btnDeleteFile').show();
                        break;
                    case 5:
                        bindFee(id, 1);
                        bindFee(id, 2);
                        $('#btnAddYS').show();
                        $('#btnDeleteYS').show();
                        $('#btnAddYF').show();
                        $('#btnDeleteYF').show();
                        break;
                }
            }
        });
    }

    function newOrder() {
        //initBtns();
        //$('#dlg').dialog('open').dialog('setTitle', '新建工作单');
        resetFrm(false);
    }
    function editOrder(id) {
        //initBtns();
        //var row = $('#tb').datagrid('getSelected');
        if (id) {
            resetFrm(false);
            //$('#dlg').dialog('open').dialog('setTitle', '编辑工作单');
            //$('#fm').form('load', row);
            //url = 'OrderFrm.aspx?id=' + row.id;
            //var id = row.OrderId;
            bindBase(id);
            bindFlow(id);
            //            bindTC(id);
            //            bindBG(id);
            //            bindCase(id);
            //            bindFee(id, 1);
            //            bindFee(id, 2);
        }
    }

    function saveOrder() {
        var validate = $('#fm').form('validate');
        if (!validate)
            return;
        var id = $('#editId').val();
        var eOrderDate = $('#eOrderDate').datebox('getValue');
        var eBizMan = $('#eBizMan').combogrid('getValue');
        var eAgent = $('#eAgent').combogrid('getValue');
        var eClient = $('#eClient').combogrid('getValue');
        var eInvoiceHeader = $('#eInvoiceHeader').val();
        var eContactInfo = $('#eContactInfo').val();
        var eCCode = $('#eCCode').val();
        var eStartPort = $('#eStartPort').combobox('getValue');
        var eEndPort = $('#eEndPort').combobox('getValue');
        var eImptAndExpt = $('#eImptAndExpt').combobox('getValue');
        var eCustomsDeadline = $('#eCustomsDeadline').datebox('getValue');
        var eStowageMethod = $('#eStowageMethod').combobox('getValue');
        var eMemo = $('#eMemo').val();
        var eHasTrailer = $('#eHasTrailer').prop("checked");
        var eHasInvoice = $('#eHasInvoice').prop("checked");
        var eIsCustoms = $('#eIsCustoms').prop("checked");
        var eIsOcean = $('#eIsOcean').prop("checked");

        WebApp.EditOrderFrm.SaveBase(id, eOrderDate, eBizMan, eAgent, eClient, eInvoiceHeader, eContactInfo,
             eCCode, eStartPort, eEndPort, eImptAndExpt, eCustomsDeadline, eStowageMethod, eMemo, eHasTrailer,
             eHasInvoice, eIsCustoms, eIsOcean, function callback(p) {

                 if (p.error) {
                     $.messager.alert('异常消息', '提交保存异常,' + p.error.Message, 'error');
                     return;
                 }

                 var res = p.value;
                 if (res) {
                     var data = res.Data;
                     var msg = res.Msg;
                     if (msg)
                         $.messager.alert('基本信息获取异常', msg, 'error');
                     else {
                         refreshParent();
                         if (id) {
                             if (data > 0) {
                                 $.messager.alert('消息', '基本信息已更新!', 'info');
                                 //$('#tb').datagrid('selectRecord', data);
                                 $('#editId').val(data);
                             }
                             else
                                 $.messager.alert('基本信息更新异常', msg, 'error');
                         }
                         else {
                             if (data > 0) {
                                 $.messager.alert('消息', '基本信息已创建!', 'info');
                                 //$('#tb').datagrid('selectRecord', data);
                                 $('#editId').val(data);
                             }
                             else
                                 $.messager.alert('基本信息创建异常', msg, 'error');
                         }
                     }
                 }
             });
    }

    function bindBase(id) {
        if (id) {
            WebApp.EditOrderFrm.GetOrderBase(id, function callback(p) {
                if (p.error) {
                    $.messager.alert('异常消息', '获取数据异常,' + p.error.Message, 'error');
                    return;
                }

                var res = p.value;
                if (res) {
                    var data = res.Data;
                    var msg = res.Msg;
                    if (msg)
                        $.messager.alert('基本信息获取异常', msg, 'error');
                    else {
                        if (data) {
                            $('#spnOrderStatus').html(data.stauts);
                            $('#spnOrderCode').val(data.code)
                            $('#editId').val(id);
                            $('#eOrderDate').datebox('setValue', DateFormatter(data.orderTime));
                            $('#eBizMan').combogrid('setValue', data.operator);
                            $('#eAgent').combogrid('setValue', data.agent);
                            $('#eClient').combogrid('setValue', data.client);
                            $('#eInvoiceHeader').val(data.invoiceHeader);
                            $('#eContactInfo').val(data.contactInfo);
                            $('#eCCode').val(data.cCode);
                            $('#eStartPort').combobox('setValue', data.startPort);
                            $('#eEndPort').combobox('setValue', data.endPort);
                            $('#eImptAndExpt').combobox('setValue', data.imptAndExpt);
                            $('#eCustomsDeadline').datebox('setValue', DateFormatter(data.customsDeadline));
                            $('#eStowageMethod').combobox('setValue', data.stowageMethod);
                            $('#eMemo').val(data.memo);
                            $('#eHasTrailer').prop("checked", data.hasTrailer);
                            $('#eHasInvoice').prop("checked", data.hasInvoice);
                            $('#eIsCustoms').prop("checked", data.isCustoms);
                            $('#eIsOcean').prop("checked", data.isOcean);

                        }
                    }
                }
            });
        }
    }

    function refreshParent() {
        window.parent.doSearch(0);
    }

    function cancelOrder() {
        var id = $('#editId').val();
        if (id) {
            $.messager.confirm('提示', '确认取消该工作单吗?', function(r) {
                if (r) {
                    WebApp.EditOrderFrm.CancelOrder(id, function callback(p) {
                        if (p.error) {
                            $.messager.alert('异常消息', '提交取消异常,' + p.error.Message, 'error');
                            return;
                        }

                        var res = p.value;
                        if (res) {
                            var data = res.Data;
                            var msg = res.Msg;
                            if (msg)
                                $.messager.alert('取消工作单异常', msg, 'error');
                            else {
                                if (data == true) {
                                    $.messager.alert('消息', '工作单信息已取消!', 'info');
                                    refreshParent();
                                }
                                else
                                    $.messager.alert('取消工作单失败', msg, 'error');
                            }
                        }
                    });
                } 
            });
        }
    }

    function saveTC() {
        var orderId = $('#editId').val();
        if (orderId) {
            var validate = $('#fmTC').form('validate');
            if (!validate)
                return;
            var eStowageArea = $('#eStowageArea').combobox('getValue');
            var eDeadline = $('#eDeadline').datetimebox('getValue');
            var eReturnPort = $('#eReturnPort').combobox('getValue');
            var eTCAgent = $('#eTCAgent').combobox('getValue');
            var eStowageContact = $('#eStowageContact').val();
            var eOpContact = $('#eOpContact').val();
            var eSpecs = $('#eSpecs').val();
            var eTCAddress = $('#eTCAddress').val();
            var eTCMemo = $('#eTCMemo').val();
            var eTCCharge = $('#eTCCharge').numberbox('getValue');
            var eIsPonderation = $('#eIsPonderation').prop("checked");
            WebApp.EditOrderFrm.SaveTC(orderId, eTCAgent, eDeadline, eTCAddress, eIsPonderation, eTCMemo, eOpContact,
         eTCCharge, eReturnPort, eSpecs, eStowageArea, eStowageContact, function callback(p) {
             if (p.error) {
                 $.messager.alert('异常消息', '提交保存异常,' + p.error.Message, 'error');
                 return;
             }

             var res = p.value;
             if (res) {
                 var data = res.Data;
                 var msg = res.Msg;
                 if (msg)
                     $.messager.alert('拖车信息更新异常', msg, 'error');
                 else {
                     if (data == true)
                         $.messager.alert('消息', '拖车信息已更新!', 'info');
                     else
                         $.messager.alert('拖车信息更新失败', msg, 'error');
                 }
             }
         });
        }
    }

    function bindTC(id) {
        if (id) {
            WebApp.EditOrderFrm.GetTC(id, function callback(p) {
                if (p.error) {
                    $.messager.alert('异常消息', '获取数据异常,' + p.error.Message, 'error');
                    return;
                }

                var res = p.value;
                if (res) {
                    var data = res.Data;
                    var msg = res.Msg;
                    if (msg)
                        $.messager.alert('拖车信息获取异常', msg, 'error');
                    else {
                        if (data) {
                            $('#eStowageArea').combobox('setValue', data.stowageArea);
                            $('#eDeadline').datetimebox('setValue', DateTimeFormatter(data.deadline))
                            $('#eReturnPort').combobox('setValue', data.returnPort);
                            $('#eTCAgent').combobox('setValue', data.agent);
                            $('#eStowageContact').val(data.stowageContact);
                            $('#eOpContact').val(data.opContact);
                            $('#eSpecs').val(data.specs);
                            $('#eTCAddress').val(data.address);
                            $('#eTCMemo').val(data.memo);
                            $('#eTCCharge').numberbox('setValue', data.charge);
                            $('#eIsPonderation').prop("checked", data.isPonderation);
                        }
                    }
                }
            });
        }
    }

    function clearTC() {
        var orderId = $('#editId').val();
        if (orderId) {
            $.messager.confirm('提示', '确认删除该拖车信息吗?', function(r) {
                if (r) {
                    WebApp.EditOrderFrm.ClearTC(orderId, function callback(p) {
                        if (p.error) {
                            $.messager.alert('异常消息', '后台处理异常,' + p.error.Message, 'error');
                            return;
                        }

                        var res = p.value;
                        if (res) {
                            var data = res.Data;
                            var msg = res.Msg;
                            if (msg)
                                $.messager.alert('拖车信息清除异常', msg, 'error');
                            else {
                                if (data == true) {
                                    $.messager.alert('消息', '拖车信息已删除!', 'info');
                                    $('#fmTC').form('clear');
                                }
                                else {
                                    $.messager.alert('拖车信息失败', msg, 'error');
                                }
                            }
                        }
                    });
                } 
            });
        }
    }

    function printWTS() {

    }

    function saveBG() {
        var validate = $('#fmBG').form('validate');
        if (!validate)
            return;
        var orderId = $('#editId').val();
        if (orderId) {
            var eBGAgent = $('#eBGAgent').combobox('getValue');
            var eCustomsStatus = $('#eCustomsStatus').combobox('getValue');
            var eTransferType = $('#eTransferType').combobox('getValue');
            var eApplyDate = $('#eApplyDate').datebox('getValue');
            var eBGPassTime = $('#eBGPassTime').datetimebox('getValue');
            var eBGTel = $('#eBGTel').val();
            var eBGAddress = $('#eBGAddress').val();
            var eBGContactMan = $('#eBGContactMan').val();
            var eBGMemo = $('#eBGMemo').val();
            var eIsOffer = $('#eIsOffer').prop("checked");
            var eIsCheck = $('#eIsCheck').prop("checked");
            var eIsPass = $('#eIsPass').prop("checked");
            var eNotice = $('#eNotice').prop("checked");
            var eIsDrawback = $('#eIsDrawback').prop("checked");
            var eIsKdsk = $('#eIsKdsk').prop("checked");

            var eNotifier = $('#eNotifier').val();
            var eReceiver = $('#eReceiver').val();
            var eRunNum = $('#eRunNum').val();
            var eStockholder = $('#eStockholder').val();
            var eBoatCorp = $('#eBoatCorp').val();
            var eBoatName = $('#eBoatName').val();
            var eBookingMemo = $('#eBookingMemo').val();
            var eDemand = $('#eDemand').val();
            var eDestination = $('#eDestination').val();
            var eBGEndPort = $('#eBGEndPort').combobox('getValue');
            var checkOffJson = JSON.stringify($('#TBHX').datagrid('getData').rows);

            WebApp.EditOrderFrm.SaveBG(orderId, eIsCheck, eIsDrawback, eIsKdsk, eNotice, eIsOffer, eIsPass, eBGMemo, eNotifier, eReceiver,
            eRunNum, eCustomsStatus, eStockholder, eTransferType, eBGAddress, eBGAgent, eApplyDate, eBoatCorp, eBoatName, eBookingMemo,
            eBGPassTime, eBGContactMan, eBGTel, eDemand, eDestination, eBGEndPort, checkOffJson, function callback(p) {
                if (p.error) {
                    $.messager.alert('异常消息', '提交保存异常,' + p.error.Message, 'error');
                    return;
                }

                var res = p.value;
                if (res) {
                    var data = res.Data;
                    var msg = res.Msg;
                    if (msg)
                        $.messager.alert('报关信息更新异常', msg, 'error');
                    else {
                        if (data == true)
                            $.messager.alert('消息', '报关信息已更新!', 'info');
                        else
                            $.messager.alert('报关信息更新失败', msg, 'error');
                    }
                }
            });
        }
    }
    function bindBG(id) {
        if (id) {
            WebApp.EditOrderFrm.GetBG(id, function callback(p) {
                if (p.error) {
                    $.messager.alert('异常消息', '获取数据异常,' + p.error.Message, 'error');
                    return;
                }

                var res = p.value;
                if (res) {
                    var data = res.Data;
                    var msg = res.Msg;
                    if (msg)
                        $.messager.alert('报关信息获取异常', msg, 'error');
                    else {
                        if (data) {
                            $('#eStowageArea').combobox('setValue', data.stowageArea);
                            $('#eDeadline').datetimebox('setValue', DateTimeFormatter(data.deadline))
                            $('#eStowageContact').val(data.stowageContact);
                            $('#eIsPonderation').prop("checked", data.isPonderation);
                            $('#eBGAgent').combobox('setValue', data.agent);
                            $('#eCustomsStatus').combobox('setValue', data.status);
                            $('#eTransferType').combobox('setValue', data.transferType);
                            $('#eApplyDate').datebox('setValue', DateFormatter(data.applyDate));
                            $('#eBGPassTime').datetimebox('setValue', DateTimeFormatter(data.passTime));
                            $('#eBGTel').val(data.contactTel);
                            $('#eBGAddress').val(data.address);
                            $('#eBGContactMan').val(data.contactMan);
                            $('#eBGMemo').val(data.memo);
                            $('#eIsOffer').prop("checked", data.isOffer);
                            $('#eIsCheck').prop("checked", data.isCheck);
                            $('#eIsPass').prop("checked", data.isPass);
                            $('#eNotice').prop("checked", data.isNotice);
                            $('#eIsDrawback').prop("checked", data.isDrawback);
                            $('#eIsKdsk').prop("checked", data.isKdsk);
                            $('#eNotifier').val(data.notifier);
                            $('#eReceiver').val(data.receiver);
                            $('#eRunNum').val(data.runNum);
                            $('#eStockholder').val(data.stockholder);
                            $('#eBoatCorp').val(data.boatCorp);
                            $('#eBoatName').val(data.boatName);
                            $('#eBookingMemo').val(data.bookingMemo);
                            $('#eDemand').val(data.demand);
                            $('#eDestination').val(data.destination);
                            $('#eBGEndPort').combobox('setValue', data.endPort);
                            bindHX(data.id);
                        }
                    }
                }
            });
        }
    }

    function deleteBG(id) {
        var orderId = $('#editId').val();
        if (orderId) {
            $.messager.confirm('提示', '确认删除该报关信息吗?', function(r) {
                if (r) {
                    WebApp.EditOrderFrm.ClearBG(orderId, function callback(p) {
                        if (p.error) {
                            $.messager.alert('异常消息', '后台处理异常,' + p.error.Message, 'error');
                            return;
                        }

                        var res = p.value;
                        if (res) {
                            var data = res.Data;
                            var msg = res.Msg;
                            if (msg)
                                $.messager.alert('报关信息清除异常', msg, 'error');
                            else {
                                if (data == true) {
                                    $.messager.alert('消息', '报关信息已删除!', 'info');
                                    $('#fmGB').form('clear');
                                }
                                else {
                                    $.messager.alert('报关信息失败', msg, 'error');
                                }
                            }
                        }
                    });
                } 
            });
        }
    }

    function bindHX(bgId) {
        if (bgId) {
            $.post('JSONHandler.ashx', {
                DataType: 'CustomsHX',
                CustomsId: bgId
            }, function(theback) {
                $('#TBHX').datagrid('loadData', theback);
            }, "json");
        }
    }

    var editIndex = undefined;
    function endHXEditing() {
        if (editIndex == undefined) { return true }
        if ($('#TBHX').datagrid('validateRow', editIndex)) {
            //            var ed = $('#TBHX').datagrid('getEditor', { index: editIndex, field: 'status' });
            //            var status = $(ed.target).combobox('getValue');
            //            $('#TBHX').datagrid('getRows')[editIndex]['productname'] = productname;
            $('#TBHX').datagrid('endEdit', editIndex);
            editIndex = undefined;
            return true;
        } else {
            return false;
        }
    }

    function appendHX() {
        if (endHXEditing()) {
            $('#TBHX').datagrid('appendRow', {});
            editIndex = $('#TBHX').datagrid('getRows').length - 1;
            $('#TBHX').datagrid('selectRow', editIndex)
                        .datagrid('beginEdit', editIndex);
        }
    }

    function removeHX() {
        if (editIndex == undefined) { return }
        $('#TBHX').datagrid('cancelEdit', editIndex)
                    .datagrid('deleteRow', editIndex);
        editIndex = undefined;
    }

    function saveHX() {
        if (endHXEditing()) {
            $('#TBHX').datagrid('acceptChanges');
        }
    }

    function rejectHX() {
        $('#TBHX').datagrid('rejectChanges');
        editIndex = undefined;
    }

    function onClickHXRow(index) {
        if (editIndex != index) {
            if (endHXEditing()) {
                $('#TBHX').datagrid('selectRow', index)
                            .datagrid('beginEdit', index);
                editIndex = index;
            } else {
                $('#TBHX').datagrid('selectRow', editIndex);
            }
        }
    }

    function selectCaseRow(rowIndex, rowData) {
        bindCargo(rowData.id);
    }

    function bindCase(orderId) {
        if (orderId) {
            $.post('JSONHandler.ashx', {
                DataType: 'Cases',
                OrderId: orderId
            }, function(theback) {
                $('#TBCase').datagrid('loadData', theback);
            }, "json");
        }
    }

    function addCase() {
        var orderId = $('#editId').val();
        if (orderId)
            openWin('EditCaseFrm.aspx?OrderId=' + orderId, "新增箱号", 500, 400);
    }

    function showCaseInfo(rowIndex, rowData) {
        var orderId = $('#editId').val();
        var caseId = rowData.id;
        if (caseId)
            openWin('EditCaseFrm.aspx?OrderId=' + orderId + "&CaseId=" + caseId, "编辑箱号", 500, 400);
    }

    function deleteCase() {
        var row = $('#TBCase').datagrid('getSelected');
        if (row) {
            $.messager.confirm('提示', '确认删除该货号吗?', function(r) {
                if (r) {
                    var id = row.id;
                    var orderId = $('#editId').val();
                    WebApp.EditOrderFrm.DeleteCase(id, orderId, function callback(p) {

                        if (p.error) {
                            $.messager.alert('异常消息', '提交删除异常,' + p.error.Message, 'error');
                            return;
                        }
                        var res = p.value;
                        if (res) {
                            var data = res.Data;
                            var msg = res.Msg;
                            if (msg)
                                $.messager.alert('删除异常', msg, 'error');
                            else {
                                if (data == true) {
                                    $.messager.alert('消息', '箱号信息已删除!', 'info');
                                    bindCase(orderId);
                                }
                                else
                                    $.messager.alert('删除箱号失败', msg, 'error');
                            }
                        }
                    });
                } 
            });
        }
    }

    function addCargo() {
        var orderId = $('#editId').val();
        var row = $('#TBCase').datagrid('getSelected');
        if (row) {
            var caseId = row.id;
            openWin('EditCargoFrm.aspx?OrderId=' + orderId + "&CaseId=" + caseId, "新增货物", 500, 400);
        }
    }

    function showCargoInfo(rowIndex, rowData) {
        var orderId = $('#editId').val();
        var row = $('#TBCase').datagrid('getSelected');
        if (row) {
            var caseId = row.id;
            var cargoId = rowData.id;
            if (orderId & cargoId) {
                openWin('EditCargoFrm.aspx?OrderId=' + orderId + "&CaseId=" + caseId + "&CargoId=" + cargoId, "编辑货物", 500, 400);
            }
        }
    }

    function bindCargo(caseId) {
        if (caseId) {
            $.post('JSONHandler.ashx', {
                DataType: 'Cargos',
                CaseId: caseId
            }, function(theback) {
                $('#TBCargo').datagrid('loadData', theback);
            }, "json");
        }
    }

    function deleteCargo() {
        var row = $('#TBCargo').datagrid('getSelected');
        if (row) {
            $.messager.confirm('提示', '确认删除该货物吗?', function(r) {
                if (r) {
                    var id = row.id;
                    var row1 = $('#TBCase').datagrid('getSelected');
                    var orderId = $('#editId').val();

                    WebApp.EditOrderFrm.DeleteCargo(id, orderId, function callback(p) {

                        if (p.error) {
                            $.messager.alert('异常消息', '提交删除异常,' + p.error.Message, 'error');
                            return;
                        }
                        var res = p.value;
                        if (res) {
                            var data = res.Data;
                            var msg = res.Msg;
                            if (msg)
                                $.messager.alert('删除异常', msg, 'error');
                            else {
                                if (data == true) {
                                    $.messager.alert('消息', '货物信息已删除!', 'info');
                                    if (row1) {
                                        var caseId = row1.id;
                                        bindCargo(caseId);
                                    }
                                }
                                else
                                    $.messager.alert('删除货物失败', msg, 'error');
                            }
                        }
                    });
                } 
            });
        }
    }

    function bindWJ() { }

    function bindFee(orderId, feeType) {
        if (orderId) {
            var tb = $('#TBYS');
            if (feeType == 2)
                tb = $('#TBYF');
            $.post('JSONHandler.ashx', {
                DataType: 'Fees',
                OrderId: orderId,
                FeeType: feeType
            }, function(theback) {
                tb.datagrid('loadData', theback);
            }, "json");
        }
    }

    function addFee(feeType) {
        var orderId = $('#editId').val();
        if (orderId) {
            //            $('#winFrame').prop('src', 'EditFeeFrm.aspx?FeeType=' + feeType + '&OrderId=' + orderId);
            //            $('#winFrame').prop('style').height = '390px';
            //            $('#winFrame').prop('style').width = '590px';
            //            $('#win').window({
            //                width: '600px',
            //                height: '400px',
            //                modal: true
            //            });
            openWin('EditFeeFrm.aspx?FeeType=' + feeType + '&OrderId=' + orderId, "新增费用", 600, 400);
        }
    }

    function showYSInfo(rowIndex, rowData) {
        var row = $('#TBYS').datagrid('getSelected');
        showFee(row);
    }

    function showYFInfo(rowIndex, rowData) {
        var row = $('#TBYF').datagrid('getSelected');
        showFee(row);
    }

    function showFee(row) {
        var orderId = $('#editId').val();
        if (row) {
            var feeId = row.id;
            var feeType = row.feeType;
            if (feeId) {
                openWin('EditFeeFrm.aspx?FeeType=' + feeType + '&OrderId=' + orderId + '&FeeId=' + feeId, "编辑费用", 600, 400);
            }
        }
    }

    function bindFlow(id) {
        if (id) {
            $.post('JSONHandler.ashx', {
                DataType: 'WorkFlow',
                OrderId: id
            }, function(theback) {
                $('#TBWF').datagrid('loadData', theback);
            }, "json");
        }
    }

    function showWF() {
        var orderId = $('#editId').val();
        var orderCode = $('#spnOrderCode').val();
        if (orderId)
            openWin('EditWorkFlowFrm.aspx?OrderCode=' + orderCode + '&OrderId=' + orderId, "工作流程", 530, 200);
    }

    function openWin(url, title, width, height) {
        $('#winFrame').prop('src', url);
        $('#winFrame').prop('style').height = height + 'px';
        $('#winFrame').prop('style').width = width + 'px';
        $('#win').window({
            title: title,
            width: width + 50,
            height: height + 50,
            modal: true
        });
    }

    function printWTS() {
        var orderId = $('#editId').val();
        if (orderId)
            window.open("ExportWTS.ashx?DataType=WTS&OrderId=" + orderId);
    }

    function bindFile(orderId) {
        if (orderId) {
            $.post('JSONHandler.ashx', {
                DataType: 'Files',
                OrderId: orderId
            }, function(theback) {
                $('#TBAttach').datagrid('loadData', theback);
            }, "json");
        }
    }

    function uploadFile() {
        var orderId = $('#editId').val();
        if (orderId)
            openWin('UploadFrm.aspx?OrderId=' + orderId, "上传文件", 300, 200);
    }

    function downloadFile() {
        var row = $('#TBAttach').datagrid('getSelected');
        if (row) {
            openWin('DownloadHandler.aspx?Id=' + row.id, "下载文件", 300, 200);
        }
    }
    
    function deleteFile() {
        var row = $('#TBAttach').datagrid('getSelected');
        var orderId = $('#editId').val();
        if (row) {
            $.messager.confirm('提示', '确认删除该文件吗?', function(r) {
                if (r) {
                    DeleteFile(row.id, orderId, function callback(p) {
                        if (p.error) {
                            $.messager.alert('异常消息', '后台处理异常,' + p.error.Message, 'error');
                            return;
                        }

                        var res = p.value;
                        if (res) {
                            var data = res.Data;
                            var msg = res.Msg;
                            if (msg)
                                $.messager.alert('文件信息删除异常', msg, 'error');
                            else {
                                if (data == true) {
                                    $.messager.alert('消息', '文件信息已删除!', 'info');
                                    bindFile(orderId);
                                }
                                else {
                                    $.messager.alert('文件信息删除失败', msg, 'error');
                                }
                            }
                        }
                    });
                } 
            });
        }
    }
</script>

</html>
